/*===== code build by mstore0.1.3 =====*/

/*===== mstoreDev/login#loginForm:0 =====*/

$$(function($it){
    
    $it.listen('keyup', {
        enterToAccountLogin: function(e){
            if(e.keyCode == 13 && $('#pwd').val()){
                $it.doLogin($('#user').val(), $('#pwd').val());
            }
        }
    });
    
    $it.click({
        accountLogin: function(){
            $it.doLogin($('#user').val(), $('#pwd').val());
        },
        guestLogin: function(e){
            e.preventDefault();
            $it.doLogin('guest', '');
        }
    });
    
    $it.extend({
        doLogin: function(user, pwd){
            $it.ajax.doLogin(user, pwd, function(resp){
                if(resp.err){
                    layer.alert(resp.err);
                }else if(resp.redirect){
                    location.href = resp.redirect;
                }
           });
        } 
    });
    
    $it.ajax({
        doLogin: function(user, pwd, callback){
            $util.ajax(function(resp){
                callback(resp);
            }, {
                cmd: 'USER_LOGIN',
                user: user,
                pwd: pwd
            });
        }
    });
    
});    
